package com.common.sentinel.config;

import com.alibaba.cloud.sentinel.feign.SentinelFeignAutoConfiguration;
import com.common.sentinel.feign.OphiuxSentinelFeign;
import feign.Feign;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

/**
 * @desc: sentinel 配置
 * @author: hhl
 * @date：2023/5/6 11:09
 */
@Configuration(proxyBeanMethods = false)
@AutoConfigureBefore(SentinelFeignAutoConfiguration.class)
public class SentinelAutoConfiguration {

	@Bean
	@Scope("prototype")//作用域：prototype 每次通过容器的getBean方法获取prototype定义的Bean时，都将产生一个新的Bean实例。
	@ConditionalOnMissingBean //当你的bean被注册之后，如果而注册相同类型的bean，就不会成功，它会保证你的bean只有一个，即你的实例只有一个，当你注册多个相同的bean时，会出现异常
	@ConditionalOnProperty(name = "feign.sentinel.enabled")
	public Feign.Builder feignSentinelBuilder() {

		return OphiuxSentinelFeign.builder();
	}

//	@Bean
//	@ConditionalOnMissingBean
//	public BlockExceptionHandler blockExceptionHandler() {
//		return new PigxUrlBlockHandler();
//	}
//
//	@Bean
//	@ConditionalOnMissingBean
//	public RequestOriginParser requestOriginParser() {
//		return new PigxHeaderRequestOriginParser();
//	}

}
